# 示例 3: 使用线程锁
import threading

lock = threading.Lock()
shared_resource = 0

def increment_resource():
    global shared_resource
    for _ in range(100000):
        with lock:
            shared_resource += 1

threads = []
for _ in range(10):
    thread = threading.Thread(target=increment_resource)
    threads.append(thread)
    thread.start()

for thread in threads:
    thread.join()

print("Final value of shared_resource:{}".format(shared_resource))













































